package com.example.demo3.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo3.entity.CodeDtc;
import com.example.demo3.entity.CodeReason;
import com.example.demo3.mapper.CodeReasonMapper;
import com.example.demo3.mapper.SparePartsMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 原因码 服务实现类
 * </p>
 *
 * @author xsyuan
 * @since 2020-03-27
 */
@Service
public class CodeReasonService extends ServiceImpl<CodeReasonMapper, CodeReason>{

    @Resource
    private SparePartsMapper sparePartsMapper;
    @Resource
    private CodeReasonMapper codeReasonMapper;


    /**
     * 分页查询
     * @param pageindex
     * @param pagesize
     * @return
     */
    public Page<CodeReason> getSelectPage(int pageindex, int pagesize){
        Page<CodeReason> page=new Page<CodeReason>().setCurrent(pageindex).setSize(pagesize);
        QueryWrapper<CodeReason> queryWrapper=new QueryWrapper<CodeReason>()
                .orderByDesc("CODE");
        codeReasonMapper.selectPage(page,queryWrapper);
        return page;
    }

    public int countPage(Map<Object,Object> map){
        return codeReasonMapper.countPage(map);
    }

    public List<CodeReason> queryPage(Map<Object,Object> map){
        return codeReasonMapper.queryPage(map);
    }
    /**
     * 新增
     * @param codeReason
     */
    public void insert(CodeReason codeReason){
        codeReason.setId(sparePartsMapper.getUUID());
        codeReasonMapper.insert(codeReason);
    }

    /**
     *修改
     * @param codeReason
     */
    public void update(CodeReason codeReason){
        codeReasonMapper.updateById(codeReason);
    }

    /**
     * 删除
     * @param id
     */
    public void delete(String id){
        QueryWrapper<CodeReason> queryWrapper = new QueryWrapper<CodeReason>()
                .eq("ID",id);
        codeReasonMapper.delete(queryWrapper);
    }
  /**
    * @description  通过Map查询【原因码】集合
    * @author: xsyuan
    * @date: 2020/3/28 10:51
    * @param  map
    * @return  List
    */
    public List<CodeReason> getByMap(Map<String,Object> map){
        return codeReasonMapper.findByMap(map);
    }
}
